PING = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやいゆえよらりるれろわいうえをがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽん"
PIAN = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤイユエヨラリルレロワイウエヲガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポン"

Base = ['a', 'i', 'u', 'e', 'o']

AIUEO_RM = [
    Base,
    ['k' + i for i in Base],
    ['sa', 'shi', 'su', 'se', 'so'],
    ['ta', 'chi', 'tsu', 'te', 'to'],
    ['n' + i for i in Base],
    ['ha', 'hi', 'fu', 'he', 'ho'],
    ['m' + i for i in Base],
    ['ya', 'i', 'yu', 'e', 'yo'],
    ['r' + i for i in Base],
    ['wa', 'i', 'u', 'e', 'wo'],
    ['g' + i for i in Base],
    ['za', 'ji', 'zi', 'ze', 'zo'],
    ['da', 'ji', 'zi', 'de', 'do'],
    ['b' + i for i in Base],
    ['p' + i for i in Base],
    ['n']
]


def word_split(sentence: str) -> list[list[str]]:
    """
    把日语平假名或片假名句子按五个五个分开为列表，存入列表中
    :param sentence: 日语平假名或片假名句子
    :return: 结果列表
    """
    one_line = 5
    split_list = []
    for pos in range(0, len(sentence), one_line):
        split_list.append(list(sentence[pos:pos + one_line]))
    return split_list


AIUEO_PING = word_split(PING)
AIUEO_PIAN = word_split(PIAN)


# print(AIUEO_PING, AIUEO_PIAN)

class Word:
    def __init__(self, rm, ping, pian):
        self.rm = rm
        self.ping = ping
        self.pian = pian


WordList = [
    Word(rm, ping, pian)
    for i, j, k in zip(AIUEO_RM, AIUEO_PING, AIUEO_PIAN)
    for rm, ping, pian in zip(i, j, k)
]


def print_table():
    """
    打印50音图
    """
    for i, j, k in zip(AIUEO_RM, AIUEO_PING, AIUEO_PIAN):
        for t, (rm, ping, pian) in enumerate(zip(i, j, k)):
            # 打印平假名和片假名
            print(f'{ping + pian:^5}', end='  ')
        # 每隔5个换行
        print()
        # 换行的时候打印一行罗马音
        for r in i:
            print(f"{r:^7}", end='  ')
        print()
        # 分隔符
        print('_' * 50)


ToPing = {' ': ' '}
Ping2Pian = {' ': ' '}
Ping2rm = {' ': ' '}
for word in WordList:
    ToPing[word.ping] = word.ping
    ToPing[word.pian] = word.ping
    ToPing[word.rm] = word.ping
    Ping2Pian[word.ping] = word.pian
    Ping2rm[word.ping] = word.rm


if __name__ == '__main__':
    print_table()
    # print(WordList)
    print(ToPing, Ping2Pian, Ping2rm)
